2020-2021 Sunseeker Telemetry and Lighting System
adc12_a_ex1_avccRef.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 
66 #include "driverlib.h"
67 
68 void main (void)
69 {
70  //Stop Watchdog Timer
71  WDT_A_hold(WDT_A_BASE);
72 
73  //P6.0 ADC option select
74  GPIO_setAsPeripheralModuleFunctionInputPin(
75  GPIO_PORT_P6,
76  GPIO_PIN0
77  );
78 
79  GPIO_setAsOutputPin(
80  GPIO_PORT_P1,
81  GPIO_PIN0
82  );
83 
84  //Initialize the ADC12_A Module
85  /*
86  * Base address of ADC12_A Module
87  * Use internal ADC12_A bit as sample/hold signal to start conversion
88  * USE MODOSC 5MHZ Digital Oscillator as clock source
89  * Use default clock divider of 1
90  */
91  ADC12_A_init(ADC12_A_BASE,
92  ADC12_A_SAMPLEHOLDSOURCE_SC,
93  ADC12_A_CLOCKSOURCE_ADC12OSC,
94  ADC12_A_CLOCKDIVIDER_1);
95 
96  ADC12_A_enable(ADC12_A_BASE);
97 
98  /*
99  * Base address of ADC12_A Module
100  * For memory buffers 0-7 sample/hold for 64 clock cycles
101  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
102  * Disable Multiple Sampling
103  */
104  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
105  ADC12_A_CYCLEHOLD_64_CYCLES,
106  ADC12_A_CYCLEHOLD_4_CYCLES,
107  ADC12_A_MULTIPLESAMPLESDISABLE);
108 
109  //Configure Memory Buffer
110  /*
111  * Base address of the ADC12_A Module
112  * Configure memory buffer 0
113  * Map input A0 to memory buffer 0
114  * Vref+ = AVcc
115  * Vr- = AVss
116  * Memory buffer 0 is not the end of a sequence
117  */
118  ADC12_A_configureMemoryParam param = {0};
119  param.memoryBufferControlIndex = ADC12_A_MEMORY_0;
120  param.inputSourceSelect = ADC12_A_INPUT_A0;
121  param.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
122  param.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
123  param.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
124  ADC12_A_configureMemory(ADC12_A_BASE ,&param);
125 
126  //Enable memory buffer 0 interrupt
127  ADC12_A_clearInterrupt(ADC12_A_BASE,
128  ADC12IFG0);
129  ADC12_A_enableInterrupt(ADC12_A_BASE,
130  ADC12IE0);
131 
132  while (1)
133  {
134  //Enable/Start sampling and conversion
135  /*
136  * Base address of ADC12_A Module
137  * Start the conversion into memory buffer 0
138  * Use the single-channel, single-conversion mode
139  */
140  ADC12_A_startConversion(ADC12_A_BASE,
141  ADC12_A_MEMORY_0,
142  ADC12_A_SINGLECHANNEL);
143 
144  //LPM0, ADC12_A_ISR will force exit
145  __bis_SR_register(LPM0_bits + GIE);
146  //for Debugger
147  __no_operation();
148  }
149 }
150 
151 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
152 #pragma vector=ADC12_VECTOR
153 __interrupt
154 #elif defined(__GNUC__)
155 __attribute__((interrupt(ADC12_VECTOR)))
156 #endif
157 void ADC12_A_ISR (void)
158 {
159  switch (__even_in_range(ADC12IV,34)){
160  case 0: break; //Vector 0: No interrupt
161  case 2: break; //Vector 2: ADC overflow
162  case 4: break; //Vector 4: ADC timing overflow
163  case 6: //Vector 6: ADC12IFG0
164  //Is Memory Buffer 0 = A0 > 0.5AVcc?
165  if (ADC12_A_getResults(ADC12_A_BASE,
166  ADC12_A_MEMORY_0)
167  >= 0x7ff){
168  //set P1.0
170  GPIO_PORT_P1,
171  GPIO_PIN0
172  );
173  } else {
174  //Clear P1.0 LED off
176  GPIO_PORT_P1,
177  GPIO_PIN0
178  );
179  }
180 
181  //Exit active CPU
182  __bic_SR_register_on_exit(LPM0_bits);
183  case 8: break; //Vector 8: ADC12IFG1
184  case 10: break; //Vector 10: ADC12IFG2
185  case 12: break; //Vector 12: ADC12IFG3
186  case 14: break; //Vector 14: ADC12IFG4
187  case 16: break; //Vector 16: ADC12IFG5
188  case 18: break; //Vector 18: ADC12IFG6
189  case 20: break; //Vector 20: ADC12IFG7
190  case 22: break; //Vector 22: ADC12IFG8
191  case 24: break; //Vector 24: ADC12IFG9
192  case 26: break; //Vector 26: ADC12IFG10
193  case 28: break; //Vector 28: ADC12IFG11
194  case 30: break; //Vector 30: ADC12IFG12
195  case 32: break; //Vector 32: ADC12IFG13
196  case 34: break; //Vector 34: ADC12IFG14
197  default: break;
198  }
199 }
200 
MPU_initThreeSegmentsParam param
void main(void)
void ADC12_A_ISR(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)